package org.example.ymcc.producer;

import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.example.ymcc.constant.MQConstants;
import org.example.ymcc.domain.MediaFile;
import org.example.ymcc.result.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class MediaProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    public JsonResult syncSend(MediaFile mediaFile){
        rocketMQTemplate.syncSend(MQConstants.MEDIA_VIDEO_UPLOAD_TOPIC+":"+MQConstants.MEDIA_VIDEO_UPLOAD_TAG,
                MessageBuilder.withPayload(JSON.toJSONString(mediaFile)).build());
        return JsonResult.success();
    }

}
